//
//  MLAEateryManageSalesVC.m
//  MagicLampApp
//
//  Created by Zheng on 2018/12/30.
//  Copyright © 2018 zheng.magic.lamp.app. All rights reserved.
//

#import "MLAEateryManageSalesVC.h"
#import "MLAEateryManageSalesCell.h"
#import "MLAEateryManageSalesModel.h"

@interface MLAEateryManageSalesVC ()

@end

@implementation MLAEateryManageSalesVC {
    NSMutableArray<MLAEateryManageSalesModel *> *modelsArr;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self configTitle:@"售卖统计"];
    
    [self.tableView registerClass:[MLAEateryManageSalesCell class] forCellReuseIdentifier:kCellID];
    self.haveRefreshHeader = YES;
    [self loadData];
}

#pragma mark - LoadData
- (void)loadData {
    [super loadData];
    
    NSDictionary *params = @{@"column":@"1"};
    
    [MLAHttpManage postHostType:MLAHttpHostType_Diancan api:kFoodSalesList params:params success:^(id  _Nonnull response, NSString * _Nonnull msg) {
        self->modelsArr = [NSMutableArray array];
        self.page++;
        self.haveRefreshFooter = YES;
        self->modelsArr = [NSMutableArray array];
        self->modelsArr = [MLAEateryManageSalesModel mj_objectArrayWithKeyValuesArray:response[@"lists"]];
        if (self->modelsArr.count < 20) {
            [self.tableView.mj_footer endRefreshingWithNoMoreData];
        }
        
        [self.tableView reloadData];
    } failure:^{
        
    }];
    
}

- (void)loadMoreData {
    NSDictionary *params = @{@"page":@(self.page),
                             @"column":@"1"};
    [MLAHttpManage postHostType:MLAHttpHostType_Api api:kFoodSalesList params:params success:^(id  _Nonnull response, NSString * _Nonnull msg) {
        self.page++;
        if ([response[@"lists"] count] < 20) {
            [self.tableView.mj_footer endRefreshingWithNoMoreData];
        } else {
            [self.tableView.mj_footer endRefreshing];
        }
        [self->modelsArr addObjectsFromArray:[MLAEateryManageSalesModel mj_objectArrayWithKeyValuesArray:response[@"lists"]]];
        [self.tableView reloadData];
    } failure:^{
        
    }];
}


#pragma mark - tableview datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return modelsArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MLAEateryManageSalesCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID forIndexPath:indexPath];
    MLAEateryManageSalesModel *model = modelsArr[indexPath.row];
    cell.model = model;
    return cell;
}




@end
